﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Processes : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Configuration.Instance.RefreshProcesses();
        lvProcesses.DataSource = Configuration.Instance.Processes;
        lvProcesses.DataBind();
    }

    protected string GetMonitorFriendlyName(object dataItem)
    {
        ProcessInfo i = (ProcessInfo)dataItem;
        switch (i.MonitoringType)
        {
            case ProcessMonitoringType.Run:
                return "Should run";                
            case ProcessMonitoringType.NotRun:
                return "Must not run";
            case ProcessMonitoringType.MinMemory:
                return string.Format("Low memory usage limit ({0})", Others.FormatSize((ulong)i.MemoryLimit));
            case ProcessMonitoringType.MaxMemory:
                return string.Format("High memory usage limit ({0})", Others.FormatSize((ulong)i.MemoryLimit));
            default:
                throw new ArgumentOutOfRangeException();
        }
    }

    protected string GetFriendlyMemoryUsage(object dataItem)
    {
        ProcessInfo i = (ProcessInfo)dataItem;
        if (!i.Memory.HasValue)
            return "not running";
        else
            return Others.FormatSize((ulong)i.Memory.Value);
    }
}
